package com.chenyun.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.lang.Assert;
import com.chenyun.boot.datasource.page.PageUtils;
import com.chenyun.common.annotation.Log;
import com.chenyun.common.enums.operlog.BusinessTypeEnum;
import com.chenyun.system.model.SmsChannel;
import com.chenyun.system.service.ISmsChannelService;
import com.chenyun.common.vo.AjaxResult;
import com.chenyun.common.vo.PageResult;
import com.chenyun.common.vo.QueryPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 短信渠道设置
 *
 * @author: Lonni
 * @date: 2022/12/27 0027 19:14
 */
@Api(tags = "短信渠道设置-admin")
@RestController
@RequestMapping("sms/channel")
@RequiredArgsConstructor
public class SmsChannelController {

    private final ISmsChannelService smsSettingService;

    @ApiOperation("获取列表")
    @PostMapping("list")
    @SaCheckPermission("sms:channel:list")
    public PageResult list(@RequestBody QueryPage queryPage) {
        List<SmsChannel> list = smsSettingService.page(queryPage);
        PageResult result = PageUtils.getPageHelperByList(list);
        return result;
    }

    @ApiOperation("添加短信渠道")
    @PostMapping("add")
    @Log(title = "添加短信渠道", businessType = BusinessTypeEnum.INSERT)
    @SaCheckPermission("sms:channel:add")
    public AjaxResult<Boolean> addSmsChannel(@RequestBody SmsChannel smsChannel) {
        return AjaxResult.SUCCESS(smsSettingService.addSmsChannel(smsChannel));
    }

    @ApiOperation("修改短信渠道")
    @PostMapping("edit")
    @Log(title = "修改短信渠道", businessType = BusinessTypeEnum.UPDATE)
    @SaCheckPermission("sms:channel:edit")
    public AjaxResult<Boolean> editSmsChannel(@RequestBody SmsChannel smsChannel) {
        return AjaxResult.SUCCESS(smsSettingService.editSmsChannel(smsChannel));
    }

    @ApiOperation("删除短信渠道")
    @PostMapping("del/{id}")
    @Log(title = "删除短信渠道", businessType = BusinessTypeEnum.DELETE)
    @SaCheckPermission("sms:channel:del")
    public AjaxResult<Boolean> removeSmsChannel(@PathVariable String id) {
        Assert.notBlank(id, "未找到指定渠道配置!");
        return AjaxResult.SUCCESS(smsSettingService.removeSmsChannel(id));
    }

    @ApiOperation("修改短信渠道状态")
    @PostMapping("changeStatus/{id}")
    @Log(title = "修改短信渠道状态", businessType = BusinessTypeEnum.UPDATE)
    @SaCheckPermission("sms:channel:changeStatus")
    public AjaxResult<Boolean> changeStatus(@PathVariable Integer id, Integer status) {
        return AjaxResult.SUCCESS(smsSettingService.changeStatus(id.toString(), status));
    }
}



